<?php
/**
 * Created by PhpStorm.
 * User: SUNHUATAO
 * Desc: 前台产品技术控制器
 */
namespace App\Modules\Home\Http\Controllers;

use App\Http\Controllers\BasicController;
use App\Modules\Manage\Model\ProductModel;
use Illuminate\Http\Request;

class ProductController extends BasicController
{
    public function __construct()
    {
        parent::__construct();
        $this->initTheme('home');
    }

    /**
     * @desc 产品技术列表
     * @param Request $request
     * @return mixed
     */
    public function productTec(Request $request)
    {
        $merge = $request->all();
        $list = ProductModel::select('id','title','cover_pic')->paginate(9);
        $listArr = $list->toArray()['data'];
        $data = [
            'merge' => $merge,
            'list' => $list,
            'listArr' => $listArr
        ];
        $this->theme->setTitle('产品中心');
        return $this->theme->scope('home/productTec', $data)->render();
    }

    /**
     * @desc 首页产品
     * @param int $limit
     * @return mixed
     */
    static function productIndex($limit = 8)
    {
        $product = ProductModel::select('id', 'cover_pic')->orderBy('updated_at', 'desc')->limit($limit)->get()->toArray();
        return $product;
    }

    /**@desc 产品详情
     * @param $id
     * @return mixed
     */
    public function productInfo($id)
    {
        $data['info'] = ProductModel::where('id', $id)->select('title', 'content', 'updated_at','keywords','description')->first()->toArray();
        $this->theme->setTitle('产品详情');
        $this->theme->setKeywords($data['info']['keywords']);
        $this->theme->setDescription($data['info']['description']);
        return $this->theme->scope('home/productInfo', $data)->render();
    }
}
